//
//  FMRegister2ViewController.m
//  PsychologyFM
//
//  Created by 杜建虎 on 16/1/16.
//  Copyright © 2016年 ZhangLuDu. All rights reserved.
//

#import "FMRegister2ViewController.h"
#import "PKRequestManager.h"
#import "FMZhuCeModel.h"
@interface FMRegister2ViewController ()

@end

@implementation FMRegister2ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = FMWhite;
    [self addAgain];
}


- (void)addAgain
{
    _iconImage1 = [[UIImageView alloc] initWithFrame:CGRectMake(kScreenWidth / 20, 110, 20, 20)];
    _iconImage1.image = [UIImage imageNamed:@"email"];
    [self.view addSubview:_iconImage1];
    
    _inputText1 = [[UITextField alloc] initWithFrame:CGRectMake(_iconImage1.left + 10 + _iconImage1.width, 110, kScreenWidth - kScreenWidth / 10, 20)];
    _inputText1.placeholder = @"验证码";
    [self.view addSubview:_inputText1];
    
    _lineLabel1 = [[UILabel alloc] initWithFrame:CGRectMake(_iconImage1.left, _iconImage1.bottom + 3, kScreenWidth - kScreenWidth / 10 , 1)];
    _lineLabel1.backgroundColor = [UIColor orangeColor];
    [self.view addSubview:_lineLabel1];
    
    
    _againButton = [UIButton buttonWithType:(UIButtonTypeCustom)];
    [_againButton setTitle:@"重新获取" forState:(UIControlStateNormal)];
    [_againButton setTitleColor:FMOrange forState:(UIControlStateNormal)];
    [_againButton addTarget:self action:@selector(againButton:) forControlEvents:(UIControlEventTouchUpInside)];
    _againButton.frame = CGRectMake(kScreenWidth - 120, 110, 80, 20);
    [self.view addSubview:_againButton];
    
    
    _iconImage2 = [[UIImageView alloc] initWithFrame:CGRectMake(kScreenWidth / 20, 160, 20, 20)];
    _iconImage2.image = [UIImage imageNamed:@"peo"];
    [self.view addSubview:_iconImage2];
    
    _inputText2 = [[UITextField alloc] initWithFrame:CGRectMake(_iconImage2.left + 10 + _iconImage2.width, 160, kScreenWidth - kScreenWidth / 10, 20)];
    _inputText2.placeholder = @"输入昵称";
    [self.view addSubview:_inputText2];
    
    _lineLabel2 = [[UILabel alloc] initWithFrame:CGRectMake(_iconImage2.left, _iconImage2.bottom + 3, kScreenWidth - kScreenWidth / 10 , 1)];
    _lineLabel2.backgroundColor = [UIColor orangeColor];
    [self.view addSubview:_lineLabel2];
    
    
    _iconImage3 = [[UIImageView alloc] initWithFrame:CGRectMake(kScreenWidth / 20, _lineLabel2.bottom + 20, 20, 20)];
    _iconImage3.image = [UIImage imageNamed:@"password"];
    [self.view addSubview:_iconImage3];
    
    _inputText3 = [[UITextField alloc] initWithFrame:CGRectMake(_iconImage3.left + 10 + _iconImage3.width, 205, kScreenWidth - kScreenWidth / 10, 20)];
    _inputText3.placeholder = @"输入密码";
    [self.view addSubview:_inputText3];
    
    _lineLabel3 = [[UILabel alloc] initWithFrame:CGRectMake(_iconImage3.left, _iconImage3.bottom + 3, kScreenWidth - kScreenWidth / 10 , 1)];
    _lineLabel3.backgroundColor = [UIColor orangeColor];
    [self.view addSubview:_lineLabel3];
    
    
    _nextButton = [UIButton buttonWithType:(UIButtonTypeCustom)];
    _nextButton.frame = CGRectMake(_iconImage1.left, _lineLabel3.bottom + 30,  kScreenWidth -  kScreenWidth / 10, 40);
    [_nextButton setTitle:@"下一步" forState:(UIControlStateNormal)];
    [_nextButton setTitleColor:FMOrange forState:(UIControlStateNormal)];
    [self.view addSubview:_nextButton];
    
    
    
}



- (void)againButton:(UIButton *)sender
{
    [self requestData];
    
}

- (void)requestData
{
    [PKRequestManager requestWithUrlString:[NSString stringWithFormat:@"http://bapi.xinli001.com/users/register_validcode.json/?phone=%@&key=c0d28ec0954084b4426223366293d190",_str] parDic:nil method:GET finish:^(NSData *data) {
        NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
        FMZhuCeModel *model = [[FMZhuCeModel alloc] init];
        [model setValuesForKeysWithDictionary:dic];
        UIAlertView *alerView = [[UIAlertView alloc] initWithTitle:@"提示" message:model.data delegate:self cancelButtonTitle:@"好的" otherButtonTitles:nil];
        alerView.tag = 1;
        [alerView show];
    } error:^(NSError *error) {
        
    }];
}



@end
